class User < ActiveRecord::Base
  acts_as_authentic
  acts_as_tree
  acts_as_authorization_subject
  acts_as_authorization_object
  
  has_many :announcements
  belongs_to :organization
  belongs_to :status
  belongs_to :employment
  belongs_to :rank
  
  validates_presence_of :email, :first_name, :last_name, :organization, :status, :employment
  
  named_scope :active, :conditions => {:deleted_at => nil}
  named_scope :deleted, :conditions => "deleted_at IS NOT NULL"
  
  alias_method :really_destroy, :destroy
  def destroy
    self.update_attribute(:deleted_at, DateTime.now)
    self.children.each{|u| u.update_attribute(:parent_id, nil) }
  end
  
  def restore
    self.update_attribute(:deleted_at, nil)
  end
end
